<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/operateTag" prefix="o"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>商品品牌管理</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<jsp:include page="/page/head.jsp"></jsp:include>
	<script type="text/javascript">
	
		$(document).ready(function(){
		
		    $('#mgrTable').datagrid({
       			height: 550, 
		        pageSize: 20,//每页显示的记录条数，默认为10  
		        pageList: [10,15,20],//可以设置每页记录条数的列表
				nowrap: true,
        		border: true,  
				striped: true,
				collapsible: false,
				url:path+'/brand/list.do',
				sortName: 'id',
				sortOrder: 'asc',
				remoteSort: false,
				idField:'id',
				pagination:true,
				rownumbers:true,
				toolbar:'#toolbar'
			});
		    
		    
		    
			var p = $('#mgrTable').datagrid('getPager');
			$(p).pagination({   
		        beforePageText: '第',//页数文本框前显示的汉字  
		        afterPageText: '页    共  {pages} 页',  
		        displayMsg: '当前显示  {from} - {to} 条记录   共  {total} 条记录'
		    });
			
		});
		
		var url;
		
		function add(){
			window.location = path+"/brand/init.do?type=add";
		}
		
		function edit(){
			var selected = $('#mgrTable').datagrid('getSelected');
			if(selected){
				window.location = path+"/brand/init.do?type=edit&brandId="+selected.id;
			}else{
				alertBox("请选择需要编辑的商品品牌！");
			}
		}
		
		function remove(){
			
			var rows = $('#mgrTable').datagrid('getSelections');
			if(rows && rows.length != 0){
				var ids = [];
				for(var i=0;i<rows.length;i++){
					ids.push(rows[i].id);
				}
				
				var submit = function (v, h, f) {
				    if (v == 'ok'){
				    	url = path +"/brand/delete.do?ids="+ids.join(',')+"&t="+new Date().getTime();
						$.ajax({
						  url: url,
						  success: function(data) {
							   if(data == "1")
							   {
								   $('#dlg').dialog('close');	
								   $('#mgrTable').datagrid('reload');
								   $('#mgrTable').datagrid('clearSelections');

							   } else {
									alertBox("操作失败！");
							   }
						  }
						});
				    }
				    	
				    return true; 
				};
				
				$.jBox.confirm("确定要删除吗？", "提示", submit);
				
			}else{
				alertBox("请选择需要删除的商品品牌！");
			}
		}
		
		function refresh(){
			$('#mgrTable').datagrid('reload');
			$('#mgrTable').datagrid('clearSelections');
		}
		
		function save(){
			if($('#fm').form('validate')){
				var data = "&name="+escape(escape($('#name').val()));
				
				$.ajax({
				  url: url,
				  data:data,
				  success: function(data) {
					   if(data == "1")
					   {
						    $('#dlg').dialog('close');	
							$('#mgrTable').datagrid('reload');
					   } else {
							alertBox("操作失败！");
					   }
				  }
				});
				
			}
		}
		
		function imageFormatter(value,rec){
          	if(value == ""){
				return "";
			}
			return "<img width='55' height='55' src='<%=basePath %>"+value+"'></img>";
        }
		
	</script>

  </head>
  
  <body>
    <div class="right">
		<h1><b>商品品牌管理</b><span><img src="<%=basePath %>images/right_h1bg2.jpg" width="3" height="29" /></span></h1>
		<div class="ri_main">
			<div id="toolbar">
				<o:Operate permissionId="99">
					<a href="javascript:void(0);" onclick="add()" class="easyui-linkbutton" iconCls="icon-add">新增</a>
				</o:Operate>
				<o:Operate permissionId="100">
					<a href="javascript:void(0);" onclick="edit()" class="easyui-linkbutton" iconCls="icon-edit">编辑</a>
				</o:Operate>
				<o:Operate permissionId="101">
					<a href="javascript:void(0);" onclick="remove()" class="easyui-linkbutton" iconCls="icon-remove">删除</a>
				</o:Operate>
				<a href="javascript:void(0);" onclick="refresh()" class="easyui-linkbutton" iconCls="icon-reload">刷新</a>
			</div>
		 	<table id="mgrTable">
		 		<thead>
		 			<tr height="20">
		 				<th field="ck" checkbox="true"></th>
		 				<th field="name" width="150" frozen="true">名称</th>
						<th field="imageUrl" width="60" formatter="imageFormatter">图片</th>
						<th field="description" width="350">描述</th>
		 			</tr>
		 		</thead>
		 	</table>  
		</div>
	</div>
  </body>
</html>